package com.seadragon.apps.doctorcard.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.seadragon.apps.doctorcard.model.Contact;
import com.seadragon.apps.doctorcard.model.Friend;

public interface FriendRepository extends JpaRepository<Friend, Long> {
	Page<Friend> findAll(Pageable pageable);

	@Query("select f from Friend f where (f.sender.id=:id1 and f.recipient.id=:id2) or (f.sender.id=:id2 and f.recipient.id=:id1)")
	Friend findByTwoContacts(@Param("id1") long id1, @Param("id2") long id2);

	Page<Friend> findBySenderOrRecipient(Contact sender, Contact recipient,	Pageable pageable);

	List<Friend> findBySenderOrRecipient(Contact sender, Contact recipient);
}